package com.example.wsappproject.mainpagefragment.subpagefragment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.wsappproject.R;
import com.example.wsappproject.mainpagefragment.subpagefragment.entity.KnowledgeSubPageEntity;

import java.util.List;

public class SubPageListAdapter extends RecyclerView.Adapter<SubPageListAdapter.SubPageHolder> {
    private List<KnowledgeSubPageEntity.DataBean.DatasBean> datas;
    private Context context;

    public SubPageListAdapter(Context context,List<KnowledgeSubPageEntity.DataBean.DatasBean> datas){
        this.datas = datas;
        this.context = context;
    }

    @Override
    public SubPageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context)
                .inflate(R.layout.item_activity_sub_page, parent, false);
        return new SubPageHolder(inflate);
    }

    @Override
    public void onBindViewHolder(SubPageHolder holder, int position) {
        KnowledgeSubPageEntity.DataBean.DatasBean datasBean = datas.get(position);
        String author = datasBean.getAuthor();
        String chapterName = datasBean.getChapterName();
        String title = datasBean.getTitle();
        String niceDate = datasBean.getNiceDate();

        holder.tvAuthor.setText(author);
        holder.tvChapterName.setText(chapterName);
        holder.tvTitle.setText(title);
        holder.tvNiceDate.setText(niceDate);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    static class SubPageHolder extends RecyclerView.ViewHolder{

        TextView tvAuthor;
        TextView tvChapterName;
        TextView tvTitle;
        TextView tvNiceDate;

        public SubPageHolder(View itemView) {
            super(itemView);
            tvAuthor = itemView.findViewById(R.id.item_search_pager_author);
            tvChapterName = itemView.findViewById(R.id.item_search_pager_chapterName);
            tvTitle = itemView.findViewById(R.id.item_search_pager_title);
            tvNiceDate = itemView.findViewById(R.id.item_search_pager_niceDate);
        }
    }
}

